/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sv.gob.dgii.controlador;


import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;
import sv.gob.dgii.entidades.DeRucCampoMsj;

/**
 *
 * @author luisrg
 */

public class DeRucCampoMsjFacade extends AbstractFacade<DeRucCampoMsj> {
    
    

    @Override
    protected EntityManager getEntityManager() {
        return Conexion.obtenerManejadorEntidades();
    }

    public DeRucCampoMsjFacade() {
        super(DeRucCampoMsj.class);
    }
    
     public Integer obtenerSiguienteCorrelativo(){
         try{
            StringBuilder str = new StringBuilder();
            str.append("select max(d.").append("idCampoMensaje").append(")+1 correlativo from ");
            str.append(super.entityClass.getSimpleName()).append(" d");
            Query q = getEntityManager().createQuery(str.toString());
            Object valor = q.getSingleResult();
            return Integer.parseInt(valor.toString());
        }catch(Exception e){
            e.printStackTrace();
            return 1;
        }
    }
    
}
